unit uniEnemyAircraft_Tank;

interface

uses
  uniEnemyAircraft,
  Classes;

type
  { EnemyAircraft_Tank }

  EnemyAircraft_Tank = class(EnemyAircraft)
  public
    constructor Create(et: EnemyType; p: array of Single; randFact: Single = 1.0);
    destructor Destroy; override;

    procedure update; override;
    procedure init; overload; override;
    procedure init(p: array of Single; randFact: Single = 1.0); overload; override;
    procedure move; override;
  end;


implementation

uses
  uniConfig,
  uniGlobal;

{ EnemyAircraft_Tank }

constructor EnemyAircraft_Tank.Create(et: EnemyType; p: array of Single; randFact: Single);
begin
  inherited Create(et, p, randFact);
  init(p, randFact);
end;

destructor EnemyAircraft_Tank.Destroy;
begin
  //inherited;
end;

procedure EnemyAircraft_Tank.init;
begin
  inherited init;
end;

procedure EnemyAircraft_Tank.init(p: array of Single; randFact: Single);
begin
  inherited init(p, randFact);

  damage := -2000.0 * uniGlobal.gameSkill;
  baseDamage := -2000.0 * uniGlobal.gameSkill;
  size[0] := 1.9;
  size[1] := 2.1;
  collisionMove := 0.1;
  vel[1] := 0.03;
end;

procedure EnemyAircraft_Tank.move;
var
  _config: Config;
  hpos: PSingle;
  diff: array[0..1] of Single;
  v1: Single;
begin
  _config := uniConfig.instance;

  if Boolean(target) then
    hpos := target.getPos
  else
    hpos := @pos;
  //float	diff[2] := { hpos[0]-pos[0], hpos[1]-pos[1] };
  diff[0] := hpos^ - pos[0]; Inc(hpos);
  diff[1] := hpos^ - pos[1];
  //float	v1;

  if (Abs(diff[0]) > 8.0) then
    v1 := 0.04
  else
    v1 := 0.04 * (Abs(diff[0]) / 8.0);
  vel[1] := 0.99 * vel[1] + 0.01 * v1;

  if (pos[1] < -3.0) then
  begin
    vel[1] := -0.1;
  end
  else
  begin
    if (pos[1] < 0.0) then vel[1] := vel[1] * 0.99;
  end;

  if (pos[0] < 0.0) then
    pos[0] := uniGlobal.speedAdj * (0.998 * pos[0] + 0.002 * (-_config.screenBoundX + 2.85))
  else
    pos[0] := uniGlobal.speedAdj * (0.998 * pos[0] + 0.002 * (_config.screenBoundX - 2.85));

  case Round(age / 50) mod 8 of
    2: pos[1] := pos[1] + uniGlobal.speedAdj * 0.05;
  else
    pos[1] := pos[1] - uniGlobal.speedAdj * vel[1];
  end;

  if (pos[0] < -_config.screenBoundX) then pos[0] := -_config.screenBoundX;
  if (pos[0] > _config.screenBoundX) then pos[0] := _config.screenBoundX;
end;

procedure EnemyAircraft_Tank.update;
var
  v, p: array[0..2] of Single;
  hpos: PSingle;
  a: Single;
  b: Single;
  dist: Single;
  ammoSpeed: Single;
  tmpInt: Integer;
  s: Single;
begin
  //v[3] = { 0.0, -0.2, 0.0 };
  v[0] := 0.0;
  v[1] := -0.2;
  v[2] := 0.0;
  //float	*hpos = game->hero->getPos();
  hpos := _hero.getPos;
  a := hpos^ - pos[0]; Inc(hpos);
  b := hpos^ - pos[1];
  ammoSpeed := 0.35 * uniglobal.speedAdj;

  Inc(age);
  Dec(shootInterval);
  pos[0] := pos[0] + secondaryMove[0] * uniGlobal.speedAdj;
  pos[1] := pos[1] + secondaryMove[1] * uniGlobal.speedAdj;
  s := (1.0 - uniGlobal.speedAdj) + (uniGlobal.speedAdj * 0.7);
  secondaryMove[0] := secondaryMove[0] * s;
  secondaryMove[1] := secondaryMove[1] * s;
  move;
  //float	p[3] := { pos[0], pos[1], pos[2] };
  p[0] := pos[0];
  p[1] := pos[1];
  p[2] := pos[2];
  p[1] := pos[1] - 1.7;
  if (Abs(a) < 4.0) then
  begin
    if (shootSwap = 0) or (shootSwap = 8) or (shootSwap = 16) then
    begin
      v[1] := -0.2;
      p[0] := pos[0] + 1.5;
      _enemyAmmo.addAmmo(0, p, v);
      p[0] := pos[0] - 1.5;
      _enemyAmmo.addAmmo(0, p, v);
    end;
    Inc(shootSwap);
    shootSwap := shootSwap mod 100;
  end;
  tmpInt := Round(age / 200);
  if not Boolean(tmpInt mod 2) then //-- omni shooters
  begin
    tmpInt := age mod 200;
    if (tmpInt < 100) then
    begin
      preFire := tmpInt / 100.0;
    end
    else
    begin
      if (tmpInt < 170) then
      begin
        if (not Boolean(age mod 10)) then
        begin
          p[1] := pos[1] - 0.45;
          //b := hpos[1]-p[1];
          b := hpos^ - p[1];
          p[0] := pos[0];
          //a := hpos[0]-p[0];
          Dec(hpos);
          a := hpos^ - p[0];
          dist := Abs(a) + Abs(b);
          shootVec[0] := 2.0 * ammoSpeed * a / dist;
          shootVec[1] := 2.0 * ammoSpeed * b / dist;
          secondaryMove[0] := secondaryMove[0] - shootVec[0] * 0.1;
          secondaryMove[1] := secondaryMove[0] - shootVec[1] * 0.1;
          _enemyAmmo.addAmmo(2, p, shootVec);
          preFire := preFire - 0.4;
          if (preFire < 0.0) then
            preFire := 0.0;
        end
        else
          preFire := preFire + 0.035;
      end
      else
        preFire := 0.0;
    end;
  end;
end;

end.

